package com.health.demo.config;

import com.baomidou.mybatisplus.annotation.DbType;
import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.Collections;

@Configuration
public class MyBaitsPlusPageConfig {

    /*
    * 分页插件 3.5以前
    * */
//    @Bean
//    public PaginationInnerInterceptor getPage(){//分页拦截器配置
//        return new PaginationInnerInterceptor();
//    }
    /*
    * 分页插件 3.5.x
    * */
    @Bean
    public PaginationInnerInterceptor paginationInnerInterceptor(){
        PaginationInnerInterceptor interceptor = new PaginationInnerInterceptor();
        //设置最大单页限制数量，默认500条，-1不受限制
        interceptor.setMaxLimit(-1L);
        interceptor.setDbType(DbType.MYSQL);

        return interceptor;
    }
    @Bean
    public MybatisPlusInterceptor mybatisPlusInterceptor(){
        MybatisPlusInterceptor mybatisPlusInterceptor = new MybatisPlusInterceptor();
        mybatisPlusInterceptor.setInterceptors(Collections.singletonList(paginationInnerInterceptor()));
        return mybatisPlusInterceptor;
    }
}
